-
Notifications
You must be signed in to change notification settings - Fork 13.3k
libcore: Add range_step and range_rev functions. #4313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
r+, though could probably use a handful of tests to guard against the ever-present "whoops, got my boundary conditions slightly wrong" bugs. I can write those if you don't feel like it though. Thanks! |
Yeah, I wasn't sure where they should go (i.e. at the bottom of the file or in the tests directory), are there any rules/conventions about this? (Also, I'm away for a week or so, and won't be able to do anything, so feel free to add the tests.) Graydon Hoare [email protected] wrote:
|
@dbaupp library tests go at the bottom of the file, language tests go in the tests directory. |
@graydon Added some tests, and found that I had met the "'negative' unsigned numbers act strangely" bug. Previously, calling I'm slightly uncomfortable about having a different API for signed vs unsigned (i.e. |
…unctions. Splits the range_step function into the two directions (up, low -> high, and down, high -> low) for the uint types, since there is no way to have `step < 0` for a backwards range.
@dbaupp Thanks. @graydon What do you think of these API changes? Is it ok to have two functions here? We could also just use |
Yeah, I'd just take an int for the step and have one variant. |
I'm unsure if it should be (Unless there is already a technique to get the type |
A whole new function for |
I vote for adding |
Considering Python's precedent, I vote for the following functions:
Where reverse is just achieved by providing a negative step value to |
I'm adding the |
Yeah. +1, these are convenience functions to be used casually; step will almost always be 1, 2, -1, -2 or a similarly small number. Iterating by MAXINT-ish steps is rare and probably best done manually or by a user-written loop / iterator. |
Merged at last! 982cf90 |
(Oh, and thanks to @dbaupp :-) |
A code like ```rust extern "C" { fn f() { fn g() {} } } ``` is incorrect and does not compile. Today rustfmt formats this in a way that is correct: ```rust extern "C" { fn f(); } ``` But this loses information, and doesn't have to be done because we know the content of the block if it is present. During development I don't think rustfmt should drop the block in this context. Closes rust-lang#4313
test suite: use CARGO_TARGET_TMPDIR for temporary build artifacts
Per #1817
Counting-down range is named
range_rev
rather thanrrange
to distinguish it from plainrange
more (obviously this can change).